package com.xyht.sca_s.student_manage_system.modules.asset.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.asset.entity.req.fixedInStorageApply.SmsAssetFixedInStorageApplyAllowReq;
import com.xyht.sca_s.student_manage_system.modules.asset.entity.req.fixedInStorageApply.SmsAssetFixedInStorageApplyReq;
import com.xyht.sca_s.student_manage_system.modules.asset.service.SmsAssetFixedInStorageApplyService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 固定资产入库申请 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-05-16
 */
@RestController
@RequestMapping("/asset/fixed/InStorage")
@SecretBody
public class SmsAssetFixedInStorageApplyController {
    @Autowired
    private SmsAssetFixedInStorageApplyService smsAssetFixedInStorageApplyService;
    @Autowired
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty(value = "提交入库申请")
    @PostMapping("/add")
    public ResponseResult addFixedInStorageApply(@RequestBody @Validated SmsAssetFixedInStorageApplyReq req, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedInStorageApplyService.addFixedInStorageApply(req, user_id);
    }

    @ApiModelProperty(value = "撤销入库申请")
    @PostMapping("/cancel")
    public ResponseResult cancelFixedInStorageApply(@RequestBody SmsAssetFixedInStorageApplyReq cancelReq, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedInStorageApplyService.cancelFixedInStorageApply(cancelReq, user_id);
    }

    @ApiModelProperty(value = "审批")
    @PostMapping("/allow")
    public ResponseResult allowAssetFixedInStorageApply(@RequestBody SmsAssetFixedInStorageApplyAllowReq allowReq, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedInStorageApplyService.allowAssetFixedInStorageApply(allowReq, user_id);
    }

    @ApiModelProperty(value = "审批列表")
    @GetMapping("/list")
    public ResponseResult getAssetFixedInStorageApplyList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                          @RequestParam(value = "apply_type") Integer apply_type,
                                                          HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedInStorageApplyService.getAssetFixedInStorageApplyList(user_id, apply_type, pageNum, pageSize);
    }

    @ApiModelProperty(value = "审批详情")
    @GetMapping("/detail")
    public ResponseResult getAssetFixedInStorageApplyDetail(@RequestParam(value = "apply_id") String apply_id,
                                                            HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedInStorageApplyService.getAssetFixedInStorageApplyDetail(apply_id, user_id);
    }

    @ApiModelProperty(value = "获取所有审批列表")
    @GetMapping("/allList")
    public ResponseResult getAssetFixedInStorageApplyAllList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                             @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                             @RequestParam(value = "allowStatus", required = false) Integer allowStatus,
                                                             @RequestParam(value = "applyName", required = false) String applyName) {
        return smsAssetFixedInStorageApplyService.getAssetFixedInStorageApplyAllList(allowStatus,applyName ,pageNum, pageSize);
    }

}

